package generator.website;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import website.*;

public class WebSiteEntityFactory
{
  protected static String nl;
  public static synchronized WebSiteEntityFactory create(String lineSeparator)
  {
    nl = lineSeparator;
    WebSiteEntityFactory result = new WebSiteEntityFactory();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package domain;" + NL + "" + NL + "public class ";
  protected final String TEXT_2 = " {" + NL;
  protected final String TEXT_3 = NL + "\tprivate String [] ";
  protected final String TEXT_4 = ";";
  protected final String TEXT_5 = NL + "\tprivate String ";
  protected final String TEXT_6 = ";";
  protected final String TEXT_7 = NL + "\tpublic String [] get";
  protected final String TEXT_8 = "(){" + NL + "\t\treturn this.";
  protected final String TEXT_9 = ";" + NL + "\t}" + NL + "\t" + NL + "\tpublic void set";
  protected final String TEXT_10 = "(String [] text){" + NL + "\t\tthis.";
  protected final String TEXT_11 = " = text;" + NL + "\t}";
  protected final String TEXT_12 = NL + "\t" + NL + "\tpublic String get";
  protected final String TEXT_13 = "(){" + NL + "\t\treturn this.";
  protected final String TEXT_14 = ";" + NL + "\t}" + NL + "\t" + NL + "\tpublic void set";
  protected final String TEXT_15 = "(String text){" + NL + "\t\tthis.";
  protected final String TEXT_16 = " = text;" + NL + "\t}";
  protected final String TEXT_17 = NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    Form form = (Form) argument;
    stringBuffer.append(TEXT_1);
    stringBuffer.append(form.getEntity().getName());
    stringBuffer.append(TEXT_2);
    
	EList<Tag> Listtag = form.getTags();
	for(Tag tag : Listtag){
		if(tag instanceof FormTag && !(tag instanceof Button)){
			if(tag instanceof Select || tag instanceof RadioButton){
    stringBuffer.append(TEXT_3);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_4);
    
			} else
    stringBuffer.append(TEXT_5);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_6);
    
		}
	}	
	for(Tag tag : Listtag){
		if(tag instanceof FormTag && !(tag instanceof Button)){
			if(tag instanceof Select || tag instanceof RadioButton){
    stringBuffer.append(TEXT_7);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_9);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_11);
    
			} else{
    stringBuffer.append(TEXT_12);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_16);
    
			}
		}
	}

    stringBuffer.append(TEXT_17);
    return stringBuffer.toString();
  }
}
